package com.jandar.util;

import java.io.IOException;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

/**
 * 安全加密工具类。
 * 
 * @author pqj
 * @version 2009-7-31
 */
public class SecurityUtils {

	private static BASE64Decoder decoder = new BASE64Decoder();
	private static BASE64Encoder encoder = new BASE64Encoder();
	
	private SecurityUtils() {}
	
	public static String base64Encoder(String str) {
		if (str == null || "".equals(str)) {
			return "";
		} else {
			return encoder.encode(str.getBytes());
		}
	}
	
	public static String base64Decoder(String str) {
		String deStr = "";
		if (str == null || "".equals(str)) {
			return deStr;
		} else {
			try {
				deStr = new String(decoder.decodeBuffer(str));
			} catch (IOException e) {
				deStr = "";
			}
		}
		
		return deStr;
	}
}
